package com.fg.pro.trade.utils;


import cn.hutool.core.util.NumberUtil;

public class TradeComputerUtils {

    /**
     * 销售额占比
     * @param salePrice 销售额
     * @param sumSalePrice 总销售额
     * @return
     */
    public static Double getSalePriceRate(Double salePrice,Double sumSalePrice){
        if(sumSalePrice==null || sumSalePrice==0d){
            return 0d;
        }
        double div = NumberUtil.div(salePrice, sumSalePrice);
        return div;
    }

    /**
     *  毛利率
     * @param salePrice 销售额
     * @param costPrice 成本额
     * @return
     */
    public static Double getGrossMargin(Double salePrice,Double costPrice){
        if(salePrice==null || salePrice==0d){
            return 0d;
        }
        Double sub = NumberUtil.sub(salePrice, costPrice);
        double div = NumberUtil.div(sub, salePrice);
        return div;
    }

    /**
     * 毛利额
     * @param salePrice
     * @param costPrice
     * @return
     */
    public static Double getGrossPrice(Double salePrice,Double costPrice){
        if(salePrice==null ){
            salePrice = 0d;
        }
        if(costPrice==null ){
            costPrice = 0d;
        }
        Double sub = NumberUtil.sub(salePrice, costPrice);
        return sub;
    }

    /**
     * 总金额/数量 = 单价
     * @param sumPrice
     * @param num
     * @return
     */
    public static Double getUnitSalePrice(Double sumPrice,Double num){
        if(num==null || num ==0d){
            return  0d;
        }
        if(sumPrice==null ){
            return 0d;
        }
        Double sub = NumberUtil.div(sumPrice, num);
        return sub;
    }



}
